package backend.ro.msg.gillardon.businesstripplanner;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.ScheduleExpression;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.TimerService;

import org.apache.log4j.Logger;

@Singleton
@Startup
public class ProgrammaticTimer implements Serializable {

  private static final Logger LOG = Logger.getLogger(ProgrammaticTimer.class);
  /**
   *
   */
  private static final long serialVersionUID = 1L;
  @Resource
  private TimerService timerService;

  public ProgrammaticTimer() {
    super();
  }

  @PostConstruct
  public void initialize() {
    ScheduleExpression expression = new ScheduleExpression();
    expression.minute("*/30").hour("*");
    this.timerService.createCalendarTimer(expression);
  }

  @Timeout
  public void execute() {
    LOG.debug("----ProgrammaticTimer: " + System.currentTimeMillis());
  }
}
